#include<iostream>
#include<string>
#include<vector>
using namespace std;

class Solution {
public:
    void duplicateZeros(vector<int>& arr) 
    {
        int n = arr.size(), cur = 0, dest = -1;
        while (cur<n)
        {
            if (arr[cur]) cur++;
            else
            {
                dest++;
                swap(arr[cur], arr[dest]);
                cur++;
            }
        }
    }
};

class Solution {
public:
    void duplicateZeros(vector<int>& arr)
    {
        int n = arr.size(), cur = 0, dest = -1;
        while (cur < n)
        {
            if (arr[cur]) dest++;
            else
            {
                dest += 2;
            }
            if (dest == n)
                break;
            cur++;
        }
        if (dest == n)
        {
            dest -= 2;
            arr[n - 1] = 0;
            cur--;
        }

        while (cur>=0)
        {
            if (arr[cur])
                arr[dest--] = arr[cur--];
            else
            {
                arr[dest--] = 0;
                arr[dest--] = 0;
                cur--;
            }
        }
    }
};

int main()
{

	return 0;
}